
function postReply(){
	var params = new Object();
	
	
	params.comment = $('#reply_comment').val();
	params.product_seq = $('#product_seq').val();
	
	$.ajax({
		url : "postReply.action",
		method : "post",
		data : params,
		dataType : "JSON",
		error : function(xhr, textStatus, errorThrown) {
			alert("에러가 발생했어요");
		},
		success : function(data, textStatus) {
			var resultReply = '<div class="product_reply product_wrapper">'
				+'<div class="product_text">' + data.member_name
				+'</div>'
				+'<div class="product_input_div">' + data.comment
				+'</div>'
				+'<div class="clear"></div>'
			+'</div>';
			$(resultReply).insertBefore(".product_write_reply");
		}
	});
}

function giveProduct(event, reply_seq, member_seq, member_name){
	if(confirm(member_name+'님에게 선물을 주시겠습니까?') == false){
		return false;
	}
	
	var target = getTarget(event);
	var target_div = $(target).clone();
	
	var params = new Object();
	
	params.member_seq = member_seq;
	params.reply_seq = reply_seq;
	params.product_seq = $('#product_seq').val();
	
	
	$.ajax({
		url : "giveProduct.action",
		method : "post",
		data : params,
		dataType : "JSON",
		error : function(xhr, textStatus, errorThrown) {
			alert("에러가 발생했어요");
		},
		success : function(data, textStatus) {
			alert('선물을 줄 분이 선택되었습니다!\n' + data.name + '의 연락처\n전화번호 : ' + data.phone + '\n이메일 : ' + data.email + '입니다.');
			$(target).slideUp('fast', function(){$(this).remove()});
			$(target_div).css('background', 'white');
			$(target_div).insertBefore(".product_reply:eq(0)");
		}
	});
}

function receiveProduct(event){
	var target = getTarget(event);
	var params = new Object();
	params.product_seq = $("#product_seq").val();
	$.ajax({
		url : "receiveProduct.action",
		method : "post",
		data : params,
		dataType : "TEXT",
		error : function(xhr, textStatus, errorThrown) {
			alert("에러가 발생했어요");
		},
		success : function(data, textStatus) {
			alert('축하합니다! 선물을 받게 되었습니다.\n선물을 올리신 '+data+'님에게 연락처를 전송하였습니다.');
			$(target).remove();
		}
	});
}

